import { defineStore } from 'pinia'
import { APP_TABBAR } from '@/sheep/config/index.js'
import { isWx } from '@/sheep/utils/is.js'
import {
  post,
  wxConfig
} from '../utils/helper.js'

const app = defineStore({
  id: 'app',
  state: () => ({
    appInfo: {},
    share: {}, // 全局分享信息
    tabbar: APP_TABBAR,
    pageH: 0
  }),
  actions: {
    async init() {
      // #ifdef H5
      if (isWx()) {
        const url = window.location.href.split('#')[0]
        post('/index/wxSdk', { url }).then(res => {
          // res.data.debug = true
          wxConfig(res.data)
        })
      }
      // #endif
      
      return Promise.resolve('wxConfig success')
    },
    setShare(value) {
      this.share = value
    }
  }
})

export default app
